﻿// Write a program that prints from given array of integers all numbers that are divisible by 7 and 3. 
// Use the built-in extension methods and lambda expressions. Rewrite the same with LINQ.

namespace _06.PrintAllNumDivBy7And3
{
    using System;
    using System.Collections.Generic;
    using System.Linq;

    public class PrintAllNumDivBy7And3
    {
        public static void Main()
        {
            int[] numbers = Enumerable.Range(1, 1000).ToArray();

            // using Lambda expression
            Console.WriteLine("Numbers divisible by 7 and 3 (using LINQ): ");
            var numDivBy21 = numbers.Where(num => num % 21 == 0);
            ConsolePrint(numDivBy21);
            Console.WriteLine();

            // using LINQ
            Console.WriteLine("Numbers divisible by 7 and 3 (using Labmda expression): ");
            numDivBy21 = from num in numbers
                         where num % 21 == 0
                         select num;
            ConsolePrint(numDivBy21);
            Console.WriteLine();
        }

        private static void ConsolePrint(IEnumerable<int> enumeration)
        {
            foreach (var item in enumeration)
            {
                Console.Write("{0} ", item);
            }
        }
    }
}
